﻿var status = 0;
var choice;
var scrolls = Array(
Array("", 1000025, 0),
Array("", 1000039, 0),
Array("", 1000040, 0),
Array("", 1000054, 0),
Array("", 1000055, 0),
Array("", 1000056, 0),
Array("", 1000057, 0),
Array("", 1001035, 0),
Array("", 1001059, 0),
Array("", 1001060, 0),
Array("", 1001079, 0),
Array("", 1001080, 0),
Array("", 1001081, 0),
Array("", 1002001, 0),
Array("", 1002002, 0),
Array("", 1002003, 0),
Array("", 1002004, 0),
Array("", 1002005, 0),
Array("", 1002006, 0),
Array("", 1002007, 0),
Array("", 1002008, 0),
Array("", 1002009, 0),
Array("", 1002010, 0),
Array("", 1002011, 0),
Array("", 1002012, 0),
Array("", 1002013, 0),
Array("", 1002014, 0),
Array("", 1002016, 0),
Array("", 1002017, 0),
Array("", 1002019, 0),
Array("", 1002020, 0),
Array("", 1002021, 0),
Array("", 1002022, 0),
Array("", 1002023, 0),
Array("", 1002024, 0),
Array("", 1002025, 0),
Array("", 1002026, 0),
Array("", 1002027, 0),
Array("", 1002028, 0),
Array("", 1002029, 0),
Array("", 1002030, 0),
Array("", 1002033, 0),
Array("", 1002034, 0),
Array("", 1002035, 0),
Array("", 1002036, 0),
Array("", 1002037, 0),
Array("", 1002038, 0),
Array("", 1002039, 0),
Array("", 1002040, 0),
Array("", 1002041, 0),
Array("", 1002042, 0),
Array("", 1002043, 0),
Array("", 1002044, 0),
Array("", 1002045, 0),
Array("", 1002046, 0),
Array("", 1002047, 0),
Array("", 1002048, 0),
Array("", 1002049, 0),
Array("", 1002050, 0),
Array("", 1002051, 0),
Array("", 1002052, 0),
Array("", 1002053, 0),
Array("", 1002054, 0),
Array("", 1002055, 0),
Array("", 1002056, 0),
Array("", 1002057, 0),
Array("", 1002058, 0),
Array("", 1002059, 0),
Array("", 1002060, 0),
Array("", 1002061, 0),
Array("", 1002062, 0),
Array("", 1002063, 0),
Array("", 1002064, 0),
Array("", 1002065, 0),
Array("", 1002066, 0),
Array("", 1002067, 0),
Array("", 1002068, 0),
Array("", 1002069, 0),
Array("", 1002072, 0),
Array("", 1002073, 0),
Array("", 1002074, 0),
Array("", 1002075, 0),
Array("", 1002080, 0),
Array("", 1002081, 0),
Array("", 1002082, 0),
Array("", 1002083, 0),
Array("", 1002084, 0),
Array("", 1002085, 0),
Array("", 1002086, 0),
Array("", 1002087, 0),
Array("", 1002088, 0),
Array("", 1002089, 0),
Array("", 1002090, 0),
Array("", 1002091, 0),
Array("", 1002092, 0),
Array("", 1002093, 0),
Array("", 1002094, 0),
Array("", 1002095, 0),
Array("", 1002096, 0),
Array("", 1002097, 0),
Array("", 1002098, 0),
Array("", 1002099, 0),
Array("", 1002100, 0),
Array("", 1002101, 0),
Array("", 1002102, 0),
Array("", 1002103, 0),
Array("", 1002104, 0),
Array("", 1002105, 0),
Array("", 1002106, 0),
Array("", 1002107, 0),
Array("", 1002108, 0),
Array("", 1002109, 0),
Array("", 1002110, 0),
Array("", 1002111, 0),
Array("", 1002112, 0),
Array("", 1002113, 0),
Array("", 1002114, 0),
Array("", 1002115, 0),
Array("", 1002116, 0),
Array("", 1002117, 0),
Array("", 1002118, 0),
Array("", 1002119, 0),
Array("", 1002120, 0),
Array("", 1002121, 0),
Array("", 1002122, 0),
Array("", 1002123, 0),
Array("", 1002124, 0),
Array("", 1002125, 0),
Array("", 1002126, 0),
Array("", 1002127, 0),
Array("", 1002128, 0),
Array("", 1002129, 0),
Array("", 1002130, 0),
Array("", 1002131, 0),
Array("", 1002132, 0),
Array("", 1002133, 0),
Array("", 1002134, 0),
Array("", 1002135, 0),
Array("", 1002136, 0),
Array("", 1002137, 0),
Array("", 1002138, 0),
Array("", 1002139, 0),
Array("", 1002140, 0),
Array("", 1002141, 0),
Array("", 1002142, 0),
Array("", 1002143, 0),
Array("", 1002144, 0),
Array("", 1002145, 0),
Array("", 1002146, 0),
Array("", 1002147, 0),
Array("", 1002148, 0),
Array("", 1002149, 0),
Array("", 1002150, 0),
Array("", 1002151, 0),
Array("", 1002152, 0),
Array("", 1002153, 0),
Array("", 1002154, 0),
Array("", 1002155, 0),
Array("", 1002156, 0),
Array("", 1002157, 0),
Array("", 1002158, 0),
Array("", 1002159, 0),
Array("", 1002160, 0),
Array("", 1002161, 0),
Array("", 1002162, 0),
Array("", 1002163, 0),
Array("", 1002164, 0),
Array("", 1002165, 0),
Array("", 1002166, 0),
Array("", 1002167, 0),
Array("", 1002168, 0),
Array("", 1002169, 0),
Array("", 1002170, 0),
Array("", 1002171, 0),
Array("", 1002172, 0),
Array("", 1002173, 0),
Array("", 1002174, 0),
Array("", 1002175, 0),
Array("", 1002176, 0),
Array("", 1002177, 0),
Array("", 1002178, 0),
Array("", 1002179, 0),
Array("", 1002180, 0),
Array("", 1002181, 0),
Array("", 1002182, 0),
Array("", 1002183, 0),
Array("", 1002184, 0),
Array("", 1002185, 0),
Array("", 1002207, 0),
Array("", 1002208, 0),
Array("", 1002209, 0),
Array("", 1002210, 0),
Array("", 1002211, 0),
Array("", 1002212, 0),
Array("", 1002213, 0),
Array("", 1002214, 0),
Array("", 1002215, 0),
Array("", 1002216, 0),
Array("", 1002217, 0),
Array("", 1002218, 0),
Array("", 1002242, 0),
Array("", 1002243, 0)
);

function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) cm.dispose();
    else {
        if (status == 0 && mode == 0) {
            cm.dispose();
            return;
        } else if (status >= 1 && mode == 0) {
            cm.sendOk("好吧，欢迎下次继续光临！.");
            cm.dispose();
            return;
        }
        if (mode == 1) status++;
        else status--;

        if (status == 0) {
            choices = "\r\n兔兔币余额：#r" + cm.getHyPay(1) + "#k个 (#r买后不支持退货哟亲#k)";
            for (var i = 0; i < scrolls.length; i++) {
                choices += "\r\n#L" + i + "##v" + scrolls[i][1] + "##z" + scrolls[i][1] + "#　#d需要#r" + scrolls[i][2] + "#d兔兔币#k#l";
            }
            cm.sendSimpleS("欢迎来到帽子1店,你想买我们商店的物品么?请选择吧：." + choices,2);
        } else if (status == 1) {
            cm.sendYesNo("你确定需要购买#v" + scrolls[selection][1] + "##t" + scrolls[selection][1] + "#?");
		choice = selection;
        } else if (status == 2) {
            var money = scrolls[choice][2];
            if (cm.getHyPay(1) < money) {
                cm.sendOk("抱歉，你没足够的兔兔币！");
                cm.dispose();
            } else {
                cm.addHyPay(money);
                cm.gainItem(scrolls[choice][1], 1);
                cm.sendOk("购买成功.");
                cm.dispose();
            }
        }
    }
}